package com.ch04.ex36;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * Created by zc on 2016/2/17.
 */
public class FactorialCalculator implements Callable<Integer> {
    private Integer number;

    public FactorialCalculator(Integer number) {
        this.number = number;
    }

    @Override
    public Integer call() throws Exception {
        int result = 1;
        if(number==0 || number==1){
            return 1;
        } else {
            for(int i=0; i<=number; i++){
                result *= i;
                TimeUnit.MILLISECONDS.sleep(20);
            }
        }

        System.out.printf("%s: %d\n", Thread.currentThread().getName(), result);
        return result;
    }
}
